package com.lijie.ljblog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lijie.ljblog.mapper.MusicMapper;
import com.lijie.ljblog.model.Music;
import com.lijie.ljblog.model.dto.MusicDTO;
import com.lijie.ljblog.service.MusicService;
import com.lijie.ljblog.util.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MusicServiceImpl extends ServiceImpl<MusicMapper,Music> implements MusicService {

    @Resource
    private MusicMapper musicMapper;

    @Value("${fileUploadUrl}")
    private String musicFilePath;

    @Override
    public Result<List<Music>> getRandomMusicList() {
        List<Music> randomMusicList = musicMapper.getRandomMusicList();
        for (Music music : randomMusicList) {
            music.setUrl(musicFilePath+music.getUrl());
            music.setCover(musicFilePath+music.getCover());
        }
        return Result.ok(randomMusicList);
    }

    @Override
    public PageInfo<Music> musicListPage( MusicDTO musicDTO) {
        PageHelper.startPage(musicDTO.getPage(),musicDTO.getSize());
        List<Music> list = this.list();
        for (Music music : list) {
            music.setUrl(musicFilePath+music.getUrl());
            music.setCover(musicFilePath+music.getCover());
        }
        return new PageInfo<>(list);
    }

    @Override
    public Result<Boolean> deleteMusic(MusicDTO musicDTO) {
        return null;
    }
}
